// Powered by jquery , system.js
(function($){
    // Create entry
    var Objects = function(){
    };
    
    Objects.prototype = {
		isNull : function(object){
	        if (object == null || typeof object == 'undefined') 
				return true;
			return false;
		},
		notNull : function(object){
			return ! this.isNull(object);
		},
        nonNull: function(){
			for(var object, len = 0; len < arguments.length; len++){
				object = arguments[len];
	            if (this.isNull(object)) {
					throw new Error('The passed viriable is null. index : ' + len);
				}
			}
        },
        nonEmpty: function(){
			for (var object, len = 0; object = arguments[len++];) {
				// The passed object cannot be null
				this.nonNull(object);
				
				// Check string type
				if (typeof object == 'string') {
					if ($.trim(object) == '') {
						throw new Error('The passed string is empty. index : ' + len);
					}
				}
			}
        },
		setIfNull : function(object, value){
			return this.isNull(object) ? value : object;
		},
		
		inverseJSON : function(json){
			return eval('(' + json + ')');
		},
		indexOfArray : function(array, o){
			for(var t = 0; t < array.length; t++){
				if(o === array[t] )
					return t;
			}
			return -1;
		},
		join : function(array, o, index){
			if(index == null || typeof index == 'undefined' || index == array.length){
				array.push(o);
				return array;
			}
			for(var i = array.length ; i >= index; i--){
				array[i] = array[i - 1];
			}
			array[index] = o;
			return array;
		},
		/**
		 * Checkout all not exists objects of the arraylist 
		 * @param {Array} all
		 * @param {Array} exists
		 * @param {Function} condition : function(exists, findout) 
		 * 	is return true means it's same 
		 */
		except : function(all, exists, condition){
			condition = $.isFunction(condition) ? condition : function(exists, findOut){
					return exists == findOut; 
				}
			var except = [];
			for(var a in all){
				var found = false;
				for(var e in exists)
					if(found = condition(exists[e], all[a]))
						break;	
				if ( !found ) except.push(all[a]);
				 
			}
			return except;
		}
    }
    
	/**
	 * Entity : StringBuffer
	 * Use for buffered string , easier and faster join
	 */
	Objects.prototype.StringBuffer = function(){
	    this.INSTANCE = [];
		this.append.apply(this, arguments);
	}
	
	Objects.prototype.StringBuffer.prototype = {
	    append : function(){
	        for(var i = 0; i < arguments.length; i++){
	            this.INSTANCE.push(arguments[i]);
	        }        
	    },toString : function(){
			console.log("###", this.INSTANCE);
	       return this.INSTANCE.join('');
	    }
	}
	
	/**
	 * To generate some code like GUID.
	 */
	Objects.prototype.guid = function(){
        return (this.guid.s4() + this.guid.s4() + "-" + this.guid.s4() + "-" 
			+ this.guid.s4() + "-" + this.guid.s4() + "-" + this.guid.s4() + this.guid.s4() + this.guid.s4());
    };
	Objects.prototype.guid.s4 = function(){
		return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
	}
	
    //Bakup the old Object
    if (window.Objects) 
        window._Objects = windown.Objects;
		
    //Set to public	
    window.Objects = new Objects();
})(jQuery);
